package com.zy.mapper;

import com.zy.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {

    @Results({
        @Result(property = "id", column = "id"),
        @Result(property = "username", column = "username"),
        @Result(property = "password", column = "password"),
        @Result(property = "userType", column = "user_type"),
        @Result(property = "balance", column = "balance")
    })
    @Select("SELECT * FROM tb_user WHERE username = #{username} AND password = #{password}")
    User findUser(@Param("username") String username, @Param("password") String password);

    @Insert("INSERT INTO tb_user (username, password, user_type, balance) VALUES (#{username}, #{password}, 1, 10000)")
    void insertUser(@Param("username") String username, @Param("password") String password);
}